<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@include file="/WEB-INF/views/include/head.jsp"%>
<html>
<head>
<meta name="decorator" content="sysDefault"
	content="text/html; charset=utf-8" />
<link href="${staticPath}/lib/datetimepicker/0.0.11/css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css">
<link href="${staticPath}/lib/chosen/1.1.0/chosen.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="${staticPath}/lib/ztree/3.5/css/zTreeStyle/zTreeStyle.css" type="text/css">
<!-- 选择对话框依赖的js -->
<script src="${staticPath}/lib/ztree/3.5/js/jquery.ztree.all-3.5.js" type="text/javascript"></script>
<script src="${staticPath}/js/jquery-dialog.js" type="text/javascript"></script>
<title>特权人操作</title>
<script type="text/javascript">
	$(function (){
		var tasks = '${tasks}';
		var obj = jQuery.parseJSON(tasks);
		var workFlowInfo = '${workFlowInfo}';
		var workflowinfo = jQuery.parseJSON(workFlowInfo);
		// 设置任务
		if (obj != null) {
			$.each(obj, function(index, task) {// index是索引,obj是第几个元素
				var opinioninfo = '<option value="'+task.taskId+'">'+task.taskName+'</option>';
				setTasks("div_editTaskExecutor","tasks",opinioninfo,index);
				setTasks("div_finishTask","tasks",opinioninfo,index);
			});
		}
		if(workflowinfo){
			if(workflowinfo.outcomeNodeIds && workflowinfo.outcomeNodes){
				var nodeIdArray = workflowinfo.outcomeNodeIds.split(";");
				var nodeNameArray = workflowinfo.outcomeNodes.split(";");
				var td_info = "";
				if(nodeIdArray.length == 1) {
					$("#opt-nextNode").css("display","none");
				} else {
					for(var i = 0 ; i < nodeIdArray.length ; i++) {
						td_info += '<input type="radio" name="nodeId" value="'+nodeIdArray[i]+'"  />'+nodeNameArray[i];
					}
					$("#opt-nextNode-div").html("<span>"+td_info+"</span>");
				}
			}
		}
	});
	
	//初始化当前任务信息
	function setTasks(parentDiv,selectId,opinionInfo,index){
		var selectIdName = "#"+selectId;
		var parentDivName = "#"+parentDiv;
		$(selectIdName,$(parentDivName)).append(opinionInfo);
		if(index == 0){
			$(selectIdName,$(parentDivName)).eq(0).attr('selected','true');
		}
	}
	$(document).ready(function() {
		//初始化时间
		$('input[name="optAction"]').change(function(){
			var value = $('input[name="optAction"]:checked').val();
			if(value == 'editTaskExecutor'){
				$("#div_editTaskExecutor").show();
				$("#div_finishTask").hide();
			}
			if(value == 'finishTask'){
				$("#div_editTaskExecutor").hide();
				$("#div_finishTask").show();
			}
		})
		
		//初始化提交按钮
		$('#btn_submit').click(function(){
			var value = $('input[name="optAction"]:checked').val();
			var result = {};
			result.type = value;
			//修改处理人
			if(value == 'editTaskExecutor'){
				result.data = getEditTaskExecutorInfo();
			}
			//任务直接通过
			if(value == 'finishTask'){
				var nodeId = $("input[name='nodeId']:checked").val();
				if($('input[name="nodeId"]').length > 1 && (nodeId == '' || nodeId == undefined)) {
					alert("请选择下一节点任务！");
					return false;
				} 
				result.data = getFinishTask();
			}
			$("#optInfo").val(JSON.stringify(result));
			$("#optForm").attr("action","${contextPath}"+"/bpm/bpmsap/adminopt");
			$("#optForm").submit();
			//window.parent.location.reload();
		})
	});
	//获取修改处理人信息
	function getEditTaskExecutorInfo(){
		var task = $("#tasks",$("#div_editTaskExecutor")).val();
		var user = $("#userId").val();
		var result = {};
		result.task = task;
		result.user = user;
		return result;
	}
	//获取任务直接通过信息
	function getFinishTask(){
		var nodeId = $("input[name='nodeId']:checked").val();
		var task = $("#tasks",$("#div_editTaskExecutor")).val();
		var result = {};
		result.task = task;
		result.nodeId = nodeId;
		return result;
	}
	//关闭本窗口
	function closeWin() {
		$("#myModal",window.parent.document).click();
	}
</script>
</head>
<body>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h2 class="panel-title">
				<span class="input-group-addon">特权人操作</span>
			</h2>
		</div>
	 <div class="panel-body">
	 	<form id="optForm" role="form" class="form-horizontal">
	 		<input type="hidden" id="proInsId" name="proInsId" value="${proInsId}"/>
	 		<input type="hidden" id="optInfo" name="optInfo""/>
	 		<div class="form-group">
				<label for="name" class="col-sm-2 control-label">操作:</label>
				<div class="col-sm-10">
					<input type="radio" name="optAction" id="optAction" value="editTaskExecutor" checked="checked">修改当前处理人</input>
		        	<input type="radio" name="optAction" id="optAction" value="finishTask">直接通过当前任务</input>
		        	 <!--  
			        <input type="radio" name="action" id="action">前后调转</input>
			        <input type="radio" name="action" id="action">终审通过</input>
			        <input type="radio" name="action" id="action">直接废弃</input>
			        -->
				</div>
			</div>
		   
		    <!-- 修改处理人 -->
		    <div id="div_editTaskExecutor">
		    	<div class="form-group">
		    		<label for="name" class="col-sm-2 control-label">任务:</label>
			    	<div class="col-sm-4">
				    	<select id="tasks" name="tasks" data-o-chosen="chosen" data-placeholder="选择一个 任务" class="form-control">
				            
				        </select>
				    </div>
		    	</div>
		    	<div class="form-group">
					<label for="name" class="col-sm-2 control-label">人员选择:</label>
					<div class="col-sm-5">
						<input type="hidden" id="userId"> 
						<div class="input-group">
					      <input type="text" class="form-control" id="userName" readonly="readonly">
					      <span class="input-group-btn">
					        <button class="btn btn-primary" id="userDialogMultiple" data-dialog="dialog" data-multiple="true" data-idField="userId" data-nameField="userName" data-authType="USER" type="button">
					        	选择
					        </button>
					      </span>
					    </div>
					</div>
				</div>
		    </div>
		    <!-- 直接通过当前任务 -->
		  	<div id="div_finishTask" style="display: none;">
		  		<div class="form-group">
		  			<label for="name" class="col-sm-2 control-label">任务:</label>
			    	<div class="col-sm-4">
				    	<select id="tasks" name="tasks" data-o-chosen="chosen" data-placeholder="选择一个任务" class="form-control">
				            
				        </select>
				    </div>
		  		</div>
		  		<div class="form-group" id="opt-nextNode">
		  			<label for="name" class="col-sm-2 control-label">下一节点任务:</label>
			    	<div class="col-sm-4" id="opt-nextNode-div">
				    	
				    </div>
		  		</div>
		  	</div>
			
			<!-- 操作 -->
			<div class="form-group" style="text-align :center">
				<input id="btn_submit" class="btn btn-primary" type="button" value="提交"/>
				<input class="btn btn-default" type="button" value="取消" onclick="closeWin();"/> 
			</div>
	 	</form>
	</div>		  		
</body>
</html>